/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

RUM_SUP_landwaypoint = {
	_mkrname = _this select 0;

	_markerpos = getmarkerpos _mkrname;
	_helo_marker_distance = _markerpos distance [getPos _helo select 0, getPos _helo select 1, 0];
	_dist1 = round _helo_marker_distance;

	_grp = _this select 1;
	_pos = getMarkerpos _mkrname;
	_wp=_grp addWaypoint [_pos, 0];
	_stg = "RUM_SUP_land = '"+(format ["%1",_helo]+"'");
	
	[_helo, _dist1, _mkrname,_callsign] spawn {
		_helo = _this select 0;
		_dist1 = _this select 1;
		_mkrname = _this select 2;
		_callsign = _this select 3;
		_distchk = true;

		_markerpos = getmarkerpos _mkrname;
		_helo_marker_distance = _markerpos distance [getPos _helo select 0, getPos _helo select 1, 0];

		while {_distchk} do {
			if ((_helo_marker_distance) <= 150) then{
				_distchk = false;
			}else{
				If (!alive _helo) then {
					player sidechat "Helo has crashed or has been shot down.";
					_distchk = false;
					exit;	
				}else{
					_helo_marker_distance = (_markerpos distance [getPos _helo select 0, getPos _helo select 1, 0]);
					_helo_height = (getPos _helo select 2);
					player sidechat format ["%1 this is %2, we are %3 meters from your DZ - OVER",RUM_COM_Callsign, _callsign, round _helo_marker_distance];
					sleep 45;
				};
			};
		};
	};

	_wp setWaypointStatements ["true", _stg];
	_wp setWaypointSpeed "MOVE";
	_wp setWaypointSpeed "NORMAL";
	_wp setWaypointCombatMode "BLUE";
	_wp setWaypointCompletionRadius 150;
	if (_helo isKindOf "plane") then {
		_helo flyInHeight RUM_SUP_flyDropHeightPLN;
	}else{
		_helo flyInHeight RUM_SUP_flyDropHeight;
	};
	// _dz;
};
RUM_SUP_moveWPNormal = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if (count _this == 2) then {_pos = getMarkerpos _mkrname} else {_pos = getpos (_this select 2)};
	_heloTakeOff2 = true;			
	while {_heloTakeOff2} do {
		_distanceToDeck = round(getposASL _helo select 2);
		_heightToHomePlate = (_distanceToDeck - (getposASL _home select 2));
		_distToHomePlate = round( _helo distance _home);
		if (_distToHomePlate >= 55) then {
			deleteWaypoint [_grp, 0];
			_wp = _grp addWaypoint [_pos, 0];
			_wp setWaypointType "MOVE";
			_wp setWaypointCombatMode "BLUE";
			_wp setWaypointSpeed "NORMAL";
			_wp setWaypointBehaviour "STEALTH";
			_wp setWaypointCompletionRadius 50;
			_helo flyInheight 45;

			sleep 5;
			_helo flyInheight RUM_THEL_flyHeight;
			_heloTakeOff2 = false;
		};
	};
};

RUM_SUP_movewaypoint = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_pos = [0,0,0];
	if (count _this < 3) then {_pos = getMarkerpos _mkrname} else {_pos = getpos (_this select 2)};
	// _varOM = true;
	// if (_varOM)then{
		// _wp=_grp addWaypoint [_pos, 0];
		// _wp setWaypointType "MOVE";
		// _wp setWaypointSpeed "NORMAL";
		// _wp setWaypointBehaviour "STEALTH";
		// _wp setWaypointCombatMode "BLUE";
		// _wp setWaypointCompletionRadius 100;
		// if(_helo iskindof "Plane")then{
			// _helo flyInHeight (RUM_SUP_flyHeightPLN + 100);
		// }else{
			// _helo flyInheight (RUM_SUP_flyHeight - 62);
		// };
		// sleep 5;
		// _wp=_grp addWaypoint [_pos, 0];
		// _wp setWaypointType "MOVE";
		// _wp setWaypointSpeed "NORMAL";
		// _wp setWaypointBehaviour "STEALTH";
		// _wp setWaypointCombatMode "BLUE";
		// _wp setWaypointCompletionRadius 100;
		// if(_helo iskindof "Plane")then{
			// _helo FlyInHeight RUM_SUP_flyHeightPLN;
		// }else{
			// _helo FlyInHeight RUM_SUP_flyHeight;
		// };
	// }else{
		_wp=_grp addWaypoint [_pos, 0];
		_wp setWaypointStatements ["true", ""];
		_wp setWaypointType "MOVE";
		_wp setWaypointSpeed "NORMAL";
		_wp setWaypointCombatMode "BLUE";
		_wp setWaypointCompletionRadius 150;
		if(_helo iskindof "Plane")then{
			_helo FlyInHeight RUM_SUP_flyHeightPLN;
		}else{
			_helo FlyInHeight RUM_SUP_flyHeight;
		};
	// };
};
RUM_SUP_moveWPTakeoff = {
	_mkrname = _this select 0;
	_grp = _this select 1;
	_helopos = [getPos _helo select 0, getPos _helo select 1, 0];
	_pos = [0,0,0];
	if(count _this < 3)then{_pos = getMarkerpos _mkrname}else{_pos = getpos (_this select 2)};
	_wp=_grp addWaypoint [_pos, 0];
	_wp setWaypointType "MOVE";
	_wp setWaypointCombatMode "BLUE";
	_wp setWaypointSpeed "LIMITED";
	_wp setWaypointBehaviour "CARELESS";
	_wp setWaypointCompletionRadius 50;
	_helo flyInheight 15;
	
	// this will set the approach altitude along its path. This will make the helo's flight more fluid and realistic on approach to the LZ
	// _heloTakeOff = true;		
	// while {_heloTakeOff} do {
		
		// _helo_marker_distance = _helopos distance [getPos _helo select 0, getPos _helo select 1, 0];
		// _helo_altitude = getPosATL _helo select 2;
		// _distFromLZ = round _helo_marker_distance;
	
		// if (_distFromLZ <= 30) then {
			// _helo flyinheight 18;
		// };
		// if (_distFromLZ <= 75) then {
			// _helo flyinheight 25;
		// };
		// if (_distFromLZ >= 100) then {
			_wp=_grp addWaypoint [_pos, 0];
			_wp setWaypointType "MOVE";
			_wp setWaypointCombatMode "BLUE";
			_wp setWaypointSpeed "NORMAL";
			_wp setWaypointBehaviour "CARELESS";
			_wp setWaypointCompletionRadius 200;
			_helo flyInheight 35;
			_heloTakeOff = false;		
		// };
		// if (_distFromLZ >= 70) then {
			// _helo flyinheight 35;
		// };
		// if (_distFromLZ >= 100) then {
			// _wp=_grp addWaypoint [_pos, 0];
			// _wp setWaypointType "MOVE";
			// _wp setWaypointCombatMode "BLUE";
			// _wp setWaypointSpeed "FULL";
			// _wp setWaypointBehaviour "CARELESS";
			// _wp setWaypointCompletionRadius 200;
			// _helo flyInheight 40;
		// };

		// debug - displays distance and altitude while in flight
		// hintsilent format ["Helo's distance from LZ: %2\nHelo's current altitude is: %3",_callsign,_distFromLZ, round _helo_altitude ];
		// sleep 0.15;
	// };
};
